#多元素查找（课上教学）
#导包
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By

#反爬
op = webdriver.ChromeOptions()
op.add_experimental_option('excludeSwitches', ['enable-automation'])
op.add_experimental_option('useAutomationExtension', False)

#打开Chrome浏览器
driver = webdriver.Chrome(options=op)
driver.get(r"https://www.baidu.com")

# aList=driver.find_elements(By.CSS_SELECTOR,"#s-top-left>a")#多元素查找CSS_SELECTOR方法
aList=driver.find_elements(By.XPATH,"//*[@id='s-top-left']/a")#多元素查找XPATH方法
print(len(aList))#（len)打印aList长度

#遍历aList里面的每一个元素

for aele in aList:# 循环取名aele
   content=aele.text
   aele.click()
   sleep(5)

   all_handles=driver.window_handles
   driver.switch_to.window(all_handles[1])
   title=driver.title
   assert content in title
   driver.close()#关闭窗口

   driver.switch_to.window(all_handles[0])
   sleep(2)

driver.quit()
